package com.qianguo.shop.base;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.View;

import com.eva.androidlibrary.image.ImageLoader;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EFragment;

/**
 * 基类Fragment
 *
 * @author GUXIA318
 * @date 2015-09-14 17:29
 */
@EFragment
public abstract class BaseFragment extends Fragment implements IBaseMethod {

    @org.androidannotations.annotations.App
    public App mApp;

    @Bean
    protected BaseUtil mBaseUtil;

    protected ImageLoader mImageLoader;

    protected abstract void initializeUI();

    @AfterViews
    public void initViews() {
        mImageLoader = mApp.getGlobalImageLoader();
        initializeUI();
    }

    @Override
    public void closeKeyboard(@NonNull Activity context) {
        mBaseUtil.closeKeyboard(context);
    }

    @Override
    public void showSnackBar(@NonNull Activity context, String content) {
        mBaseUtil.showSnackBar(context, content);
    }

    @Override
    public void showSnackBar(@NonNull Activity context, String content, String actionText, View.OnClickListener listener) {
        mBaseUtil.showSnackBar(context, content, actionText, listener);
    }

    @Override
    public void showToast(@NonNull Context context, String content) {
        mBaseUtil.showToast(context, content);
    }

    @Override
    public void showToast(@NonNull Context context, String content, int gravity) {
        mBaseUtil.showToast(context, content, gravity);
    }

    @Override
    public void showLoadingDialog(@NonNull Context context) {
        mBaseUtil.showLoadingDialog(context);
    }

    @Override
    public void closeLoadingDialog() {
        mBaseUtil.closeLoadingDialog();
    }

    @Override
    public void showDialog(@NonNull Context context, String title, String warningMsg, View.OnClickListener confirmClickListener, View.OnClickListener cancelClickListener) {
        mBaseUtil.showDialog(context, title, warningMsg, confirmClickListener, cancelClickListener);
    }

    @Override
    public void showDialog(@NonNull Context context, String title, String warningMsg, String confirm, String cancel, View.OnClickListener confirmClickListener, View.OnClickListener cancelClickListener) {
        mBaseUtil.showDialog(context, title, warningMsg, confirm, cancel, confirmClickListener, cancelClickListener);
    }

    @Override
    public void showWarningDialog(@NonNull Context context, String title, String warningMsg, View.OnClickListener onOkBtnClickListener) {
        mBaseUtil.showWarningDialog(context, title, warningMsg, onOkBtnClickListener);
    }

    public Context getApplicationContext() {
        if (getActivity() == null) {
            return null;
        }
        return getActivity().getApplicationContext();
    }

    @Override
    public void closeDialog() {
        mBaseUtil.closeDialog();
    }
}
